package com.cskaoyan.controller;

import com.cskaoyan.bean.MarketBrand;
import com.cskaoyan.bean.bo.MarketBrandBo;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.MarketBrandVo;
import com.cskaoyan.service.AdminBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yi
 * @date 2022/10/13 21:30
 */
@RestController
@RequestMapping("admin/brand")
public class AdminBrandController {
    @Autowired
    AdminBrandService adminBrandService;

    @RequestMapping("list")
    public BaseRespVo list(Integer id, String name, BasePageInfo basePageInfo) {
        CommonData<MarketBrand> data = adminBrandService.queryByIdAndName(id, name, basePageInfo);
        return BaseRespVo.ok(data, "成功");
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody MarketBrand brand) {
        MarketBrandVo brandVo = adminBrandService.createBrand(brand);
        return BaseRespVo.ok(brandVo, "成功");
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketBrand brand) {
        MarketBrand brand1 = adminBrandService.updateBrand(brand);
        return BaseRespVo.ok(brand1, "成功");
    }
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketBrand brand) {
        adminBrandService.deleteBrand(brand.getId());
        return BaseRespVo.ok("成功");
    }
}
